package com.com.typhoon.controller;

import com.com.typhoon.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/11/20 下午3:54
 * @description
 * @modified by
 * @since V2.0.0
 */
@RestController
@RequestMapping("/user")
public class IndexController {


    @GetMapping("/login")
    public String login(String account, String password,HttpSession session) {
        if("typhoon".equalsIgnoreCase(account) && "123".equalsIgnoreCase(password)) {
            session.setAttribute(session.getId(),User.builder()
                    .account(account)
                    .password(password)
                    .build());
         return  "success";
        }
        return "failed";
    }
    @GetMapping(value = "/logout")
    public String logout(HttpSession session){
        session.removeAttribute(session.getId());
        return "user logout success";
    }

    @GetMapping(value = "/{account}")
    public User getUser(@PathVariable("account") String account) {
        return User.builder()
                .account(account)
                .build();
    }





}
